package cn.admin.service.impl;

import cn.admin.dao.IdCardPictureMapper;
import cn.admin.entity.IdCardPicture;
import cn.admin.service.IdCardPictureService;
import cn.admin.tools.ImageConvert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 13:50 2019/4/21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class IdCardPictureServiceImpl implements IdCardPictureService {

    @Autowired
    private IdCardPictureMapper idCardPictureMapper;


    @Override
    public IdCardPicture getCardById(HttpServletRequest request, int userId) throws Exception {
        IdCardPicture cardById = idCardPictureMapper.findCardById(userId);
        if (null == cardById) {
            byte[] bytes = ImageConvert.image2byte(request.getSession().getServletContext().getRealPath("/IdCard/not_idcard.png"));
            return new IdCardPicture(bytes, bytes);
        }
        return cardById;
    }


}
